package com.wangyf.thread2;

/**
 * 有问题的程序
 * @author wangyf
 * @date 2021/7/21 20:45
 */
public class T11_NoVisibility {

    private static boolean ready = false;
    private static int num ;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            ready = false;
            num = 0;
            Thread t1 = new Thread(() -> {
                while (!ready) {
                    Thread.yield();
                }
                if (num == 0)
                System.out.println(num);
            });
            t1.start();
            num = 100;
            ready = true;
            t1.join();
        }
    }
}
